using System;
using System.Xml;
using DesignByContract;
using Outcoding.GraphGenerator.Entities;
using Outcoding.GraphGenerator.Util.Logging;

namespace Outcoding.GraphGenerator.Composition{
    public class SlideCollectionBuilder : BuilderBase{

        private readonly string mNodeName = XmlTagNames.slidecollection.ToString();

        private XmlNode mNode;

        private string mNodePath{
            get { return "/presentation/" + mNodeName; }
        }

        public override void SelectNode(XmlDocument document){
            if (document != null) 
                mNode = document.SelectSingleNode(mNodePath);
        }

        public override void Compose(){
            try{
                BuildObject(mNode);
            }
            catch (PreconditionException preExc){
                LogManager.Instance.LogWarning("SlideCollection entity could not be created; process aborted.", preExc);
            }
        }

        public override void Compose(XmlNode node){
            throw new Exception("The method or operation is not implemented.");
        }

        public override void AppendToParent(object parent){
            var presentation = (Presentation) parent;
            presentation.Slides = (SlideCollection) Product;
        }

        private void BuildObject(XmlNode slideCollectionXmlNode){
            mProduct = new SlideCollection();
        }
    }
}